{% extends "admin/layout.html" %}

{% block head %} 
<title>{{ _(config["WEBSITE_NAME"]) }} - {{ _("Queue Wiki Posts") }}</title>
<script type="text/javascript" src="{{ url_for('static', filename='vendors/tinymce/tinymce.min.js') }}"></script>
<script type="text/javascript">
  function activateTiny(target) {
      tinymce.init({ 
          selector: target,
          plugins : "advlist autolink link image lists charmap print preview textcolor emoticons directionality fullscreen table wordcount code",
          toolbar : "undo redo | styleselect | alignleft aligncenter alignright alignjustify ltr rtl | outdent indent blockquote removeformat bullist numlist | forecolor backcolor underline strikethrough italic bold | insertdatetime code preview emoticons table link image",
      });
  }    
</script>
{% endblock %}

{% block body %}
{% for post in query %}
  <div id="m{{ post.Id }}" class="modal fade" role="dialog" style="display: none;">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header">
                  <button type="button" class="close btn" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">{{ _("Perview") }}</h4>
              </div>
              <div class="modal-body">
                  {{ post.content|safe }}
              </div>
              <div class="modal-footer">
                  <button type="button" class="btn btn-default" data-dismiss="modal">{{ _("Close") }}</button>
              </div>
          </div>
      </div>
  </div>
  <div id="me{{ post.Id }}" class="modal fade" role="dialog" style="display: none;">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header">
                  <button type="button" class="close btn" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">{{ _("Edit") }}</h4>
              </div>
              <form method="POST" action="{{ url_for('admin.queue_config') }}">
                <input name="_csrf_token" type="hidden" value="{{ csrf_token() }}">  
                <input type="hidden" name="post-header" value="{{ post.address }}">
                <div class="modal-body">
                    <input type="hidden" name="id" value="{{ post.Id }}">
                    <textarea name="content" id="ma{{ post.Id }}">{{ post.content|safe }}</textarea>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">{{ _("Close") }}</button>
                    <input type="submit" name="submit" class="btn btn-default" value="{{ _('Save') }}">
                </div>
              </form>
          </div>
      </div>
  </div>
{% endfor %}        

{% if get_flashed_messages() %}
  <div class="alert alert-warning">
  </div>
  <div class="alert alert-danger alert-dismissible fade in" role="alert">
      <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
      <strong>{{ _("Warning!") }}</strong> {{ _("Post address is not avaliable.") }}
  </div>
{% endif %}
<div class="right_col" role="main" style="min-height: 939px;">
  <div class="">
    <div class="page-title">
      <div class="title_left">
        <h3>{{ _("Queue Wiki Posts") }}</h3>
      </div>
    </div>            
    <div class="clearfix"></div>
    <div class="row">
      <div class="col-md-12">
        <div class="x_panel">
          <div class="x_content">
            <table class="table table-striped projects">
              <thead>
                <tr>
                  <th style="width: 5%">{{ _("ID") }}</th>
                  <th style="width: 20%">{{ _("Page Address") }}</th>
                  <th style="width: 20%">{{ _("Language") }}</th>
                  <th style="width: 30%">{{ _("URL") }}</th>
                  <th style="width: 25%">{{ _("Edit") }}</th>
                </tr>
              </thead>
              <tbody>
                {% for post in query %}
                  <tr>
                    <td>{{ post.Id }}</td>
                    <td>{{ post.address }}</td>
                    <td>{{ post.default_lang }}</td>
                    <td>
                      <a>{{ post.url }}</a>
                    </td>
                    <td>
                      <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#me{{ post.Id }}" onclick="activateTiny('#ma{{ post.Id }}')">{{ _("Edit") }}</button>
                      <button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#m{{ post.Id }}">{{ _("Perview") }}</button>
                      <form method="POST" action="{{ url_for('admin.queue_config') }}">
                        <input name="_csrf_token" type="hidden" value="{{ csrf_token() }}">
                        <input type="hidden" name="id" value="{{ post.Id }}">
                        <input type="submit" name="submit" style="display: inline-block !important;" class="btn btn-info btn-sm" value="{{ _('Delete') }}">
                        {% if post.orginal_id.isdigit() %}
                            <input type="submit" name="submit" style="display: inline-block !important;" class="btn btn-info btn-sm" value="{{ _('Merge') }}">
                        {% else %}
                            <input type="submit" name="submit" style="display: inline-block !important;" class="btn btn-info btn-sm" value="{{ _('Publish') }}">
                        {% endif %}
                      </form>
                    </td>
                  </tr>
              {% endfor %}
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}